package io.example.service.impl;

import io.example.entity.Book;
import io.example.repository.BookRepository;
import io.example.service.BookAsyncService;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description: BookAsyncServiceImpl.java .<br>
 * <p>Created Time: 2020/10/22 16:29 </p>
 *
 * @author <a href="mail to: mengxiangyuancc@gmail.com" rel="nofollow">孟祥元</a>
 */
@Service
public class BookAsyncServiceImpl implements BookAsyncService {
    @Autowired BookRepository bookRepository;

    @Override
    public void add(Book book, Handler<AsyncResult<Book>> resultHandler) {
        resultHandler.handle(Future.succeededFuture(bookRepository.save(book)));
    }

    @Override
    public void getAll(Handler<AsyncResult<List<Book>>> resultHandler) {
        resultHandler.handle(Future.succeededFuture(bookRepository.findAll()));
    }
}
